home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 266_01 / pxlib.c < prev    next >
C/C++ Source or Header  |  1990-04-19  |  3KB  |  133 lines

  1. /*       Front End Plot Drawing Routines      File: PXLIB.C
  2.             08-30-87
  3.          WITH MATHLIB
  4. */
  5. #include "PLOX.H"
  6. #include "stdio.h"
  7. #include "PXLIB.H"
  8. #define SWAP(A,B) {A=A^B;B=B^A;A=A^B;}
  9. #define putw(W,F) fwrite(&W,sizeof(int),1,F) /* for ANSI C compatibility */
  10.  
  11. FILE   *Plot;
  12.  
  13. void PX_Close (X,Y)
  14. /*   ========      Close the plot file. */
  15. int X,Y;
  16. {
  17.   putc(CLOS,Plot);
  18.   putw(X,Plot);
  19.   putw(Y,Plot);
  20.   fclose(Plot);
  21. }
  22.  
  23. void PX_Dot (X,Y)
  24. /*   ======        Turn on X,Y pixel. */
  25. int X,Y;
  26. {
  27.   putc(ON,Plot);
  28.   putw(X,Plot);
  29.   putw(Y,Plot);
  30. }
  31.  
  32. void PX_Draw (X,Y)
  33. /*   =======       Draw vector to X,Y pixel loc. */
  34. int X,Y;
  35. {
  36.   putc(MARK,Plot);
  37.   putw(X,Plot);
  38.   putw(Y,Plot);
  39. }
  40.  
  41. void PX_Hue (int Color) {
  42. /*   ======                Set current color */
  43.   putc(HUE,Plot);
  44.   putw(Color,Plot);
  45. }
  46.  
  47. void PX_Hatch (X1,Y1,X2,Y2)
  48. /*   ========              Hatch an area */
  49. int X1,Y1,X2,Y2;
  50. {
  51.   if (X1>X2) SWAP(X1,X2)
  52.   if (Y1>Y2) SWAP(Y1,Y2)
  53.   putc(FILL,Plot);
  54.   putw(X1,Plot);
  55.   putw(Y1,Plot);
  56.   putw(X2,Plot);
  57.   putw(Y2,Plot);
  58. }
  59.  
  60. void PX_Margin (Column)
  61. /*   =========         Set plot left margin */
  62. int Column;
  63. {
  64.   putc(MRGN,Plot);
  65.   putw(Column,Plot);
  66. }
  67.  
  68. void PX_Move (X,Y)
  69. /*   =======       Move to X,Y pixel loc. */
  70. int X,Y;
  71. {
  72.   putc(MOVE,Plot);
  73.   putw(X,Plot);
  74.   putw(Y,Plot);
  75. }
  76.  
  77. void PX_Open()
  78. /*   =======   Open the plot file */
  79. {
  80.   Plot = fopen("PLOTCOM.DAT","wb");
  81. }
  82.  
  83. void PX_Origin (X,Y)
  84. /*   =========      Set new plot origin */
  85. int X,Y;
  86. {
  87.   putc(ORIG,Plot);
  88.   putw(X,Plot);
  89.   putw(Y,Plot);
  90. }
  91. /*@@*/
  92. void PX_Style (Type,Spacing)
  93. /*   ========               Set hatching pattern */
  94. int Type,Spacing;
  95. {
  96.   putc(HTYP,Plot);
  97.   putw(Type,Plot);
  98.   putw(Spacing,Plot);
  99. }
  100.  
  101. void PX_Symbol (Shape)
  102. /*   =========      Draw symmetrical, centered symbol */
  103. int Shape;       /* at current location */
  104. {
  105.   putc(SYMB,Plot);
  106.   putc(Shape,Plot);
  107. }
  108.  
  109. void PX_Text (X,Y,Size,Dir,Text_Ptr)
  110. /*   =======      Draws a string of text */
  111.  
  112. int  X,Y;       /* lower, left corner of text start */
  113. int  Size;      /* font number (1 or 2)             */
  114. char Dir;       /* 'H' = horizontal, 'V' = vertical */
  115. char *Text_Ptr; /* the text string                  */
  116. {
  117.   if (Size==2) putc(TX2H+(Dir=='V'),Plot);
  118.   else         putc(TXTH+(Dir=='V'),Plot);
  119.   putw(X,Plot);
  120.   putw(Y,Plot);
  121.   for (; *Text_Ptr!='\0'; Text_Ptr++)
  122.     putc(*Text_Ptr,Plot);
  123.   putc(0,Plot);
  124. }
  125.  
  126. void PX_Trail (Mark)
  127. /*   ========       Sets the line type */
  128. int Mark;
  129. {
  130.   putc (LTYP, Plot);
  131.   putc (Mark, Plot);
  132. }
  133.